<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/mobile/include/taglib.jsp"%>
<html>
<head>
	<title>商品分类管理</title>
	<%@include file="/WEB-INF/views/mobile/include/head.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#listForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
        
        //增加或删除
        function delClassify(){
       		var id = $("input[name='rId']").val();
			window.location.href = "${ctx}/ivm/product/classify/delete?id="+id;
		}
		
		//打开删除确认面板
		function checkDelete(id){
			$("#delPopup").popup("open");
			$("input[name='rId']").val(id);
		}
		
		function updateSort() {
			if(${fn:length(list)==0}){
        		$('#popup p').text("暂无可保存的信息.");
        		openPopup();
        		return;
        	}
	    	$("#listForm").attr("action", "${ctx}/ivm/product/classify/updateSort");
	    	$("#listForm").submit();
    	}
	</script>
</head>
<body data-role="page">
	<div data-role="header" class="ui-header" data-position="fixed" data-tap-toggle="false">
		<div data-role="controlgroup" data-type="horizontal" class="ui-btn-left">
			<a href="${ctx }/ivm/merchant/set"><img class="head-back-icon" src="${ctxFront}/images/head/android/back.png"/></a>
	    </div>
	    <h1>商品分类</h1>
		<div data-role="controlgroup" data-type="horizontal" class="ui-mini ui-btn-right">
	    	<a href="${ctx}/ivm/product/classify/form" class="float-right"><img class="head-add-icon" src="${ctxFront}/images/head/android/add.png"/></a>
			<a href="#" onclick="updateSort()" class="float-right"><img class="head-save_sort-icon" src="${ctxFront}/images/head/android/save_sort.png"/></a>
	    </div>
	</div>

	<div role="main" class="ui-content">
		<div id="popup" data-role="popup" data-position-to="window" data-overlay-theme="a" data-theme="b" class="ui-content">
		  <p></p>
		</div>
		<tags:mbmessage content="${message}"/>
		<c:if test="${page.count != 0}">
		<form id="listForm" method="post">
		<ul data-role="listview" data-divider-theme="a">
		<c:forEach items="${list}" var="productClassify" varStatus="ps">
			<li data-icon="false">
				<a style="${productClassify.parent.id!=null?'background-color: #ffffff;':''}" href="${ctx}/ivm/product/classify/form?id=${productClassify.id}">
					<c:if test="${productClassify.parent.id!=null}">&nbsp;&nbsp;&nbsp;&nbsp;</c:if>${productClassify.name}
				</a>
	       		<p class="ui-li-aside" style="margin-right: 50px; margin-top: -10px;">
	        		<shiro:hasPermission name="ivm:product:classify:edit">
						<input type="hidden" name="ids" value="${productClassify.id}"/>
						<input name="sorts" type="text" value="${productClassify.sort}" style="width:50px;margin:0;padding:0;text-align:center;" class="required digits">
					</shiro:hasPermission>
					<shiro:lacksPermission name="ivm:product:classify:edit">
						${productClassify.sort}
					</shiro:lacksPermission>
	        	</p>
	       		<p class="ui-li-aside" style="margin-right:-20px">
	       			<shiro:hasPermission name="ivm:product:classify:edit">
	       			<img class="ui-li-del" onclick="checkDelete('${productClassify.id}')" src="${ctxFront }/images/red_del.png"/>
	       			</shiro:hasPermission>
	       		</p>
	       	</li>
		</c:forEach>
		</ul>
		</form>
		</c:if>
		<c:if test="${fn:length(list) == 0}">
			暂无商品分类.
		</c:if>
		<div data-role="popup" id="delPopup" data-overlay-theme="b" data-theme="a" data-dismissible="false" style="max-width:400px;">
			<div data-role="header" data-theme="a">
		    	<h1>删除</h1>
		    </div>
		    <div role="main" class="ui-content">
		        <h3 class="ui-title">是否确定删除？</h3>
		        <input type="hidden" id="rId" name="rId" value=""/>
		        <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-a" onclick="delClassify()" data-transition="flow">确定</a>
		        <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-a" data-rel="back">返回</a>
		    </div>
		</div>
	</div>
	<%@include file="/WEB-INF/views/mobile/layouts/menu.jsp" %>
</body>
</html>
